package com.ruoyi.wechat.service.impl;

import com.ruoyi.common.utils.ConvertUtils;
import com.ruoyi.common.utils.uuid.IdUtils;
import com.ruoyi.wechat.domain.Project;
import com.ruoyi.wechat.domain.WxActivity;
import com.ruoyi.wechat.domain.WxProject;
import com.ruoyi.wechat.mapper.ProjectMapper;
import com.ruoyi.wechat.service.IWxProjectService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>ClassName : WxProjectServiceImpl</p>
 * <p>Description : </p>
 *
 * @author 孙伟光
 * @version 1.0
 * @date 2024/7/31 15:51
 */
@Service
public class WxProjectServiceImpl implements IWxProjectService {

    @Autowired
    private ProjectMapper projectMapper;

    /**
     * 根据营地Id查询该营地的所有其他项目
     * @param campId 营地Id
     * @return 该营地的项目列表
     */
    @Override
    public List<WxProject> getInfoByCampId(String campId) {
        //封装条件
        Project project = new Project();
        project.setCampId(campId);
        project.setApprove("1");
        //查询项目列表
        List<Project> list = projectMapper.selectProjectList(project);
        //数据类型转换
        if (list != null && list.size() > 0) {
            return ConvertUtils.sourceToTarget(list, WxProject.class);
        }
        return null;
    }

    /**
     * 根据项目Id获取详细信息
     * @param projectId 项目Id
     * @return 项目对象
     */
    @Override
    public WxProject getInfo(String projectId) {
        //根据项目Id查询对象
        Project project = projectMapper.selectProjectByProjectId(projectId);
        //数据类型转换
        WxProject wxProject = ConvertUtils.sourceToTarget(project, WxProject.class);
        //返回对象
        return wxProject;
    }

    /**
     * 新增项目
     *
     * @param wxProject 项目
     * @return 结果
     */
    @Override
    public int insertWxProject(WxProject wxProject) {
        //设置条件
        wxProject.setProjectId(IdUtils.randomUUID());
        wxProject.setApprove("0");
        //数据类型转换
        Project project = ConvertUtils.sourceToTarget(wxProject, Project.class);
        //新增项目
        return projectMapper.insertProject(project);
    }

    /**
     * 修改项目
     *
     * @param wxProject 项目
     * @return 结果
     */
    @Override
    public int updateWxProject(WxProject wxProject) {
        //设置条件
        wxProject.setApprove("0");
        //数据类型转换
        Project project = ConvertUtils.sourceToTarget(wxProject, Project.class);
        //修改项目
        return projectMapper.updateProject(project);
    }

    /**
     * 删除项目信息
     *
     * @param projectId 项目主键
     * @return 结果
     */
    @Override
    public int deleteWxProjectByProjectId(String projectId) {
        return projectMapper.deleteProjectByProjectId(projectId);
    }
}
